/*
 *****************************************************************************
 * Copyright (C) 2005-2011 UC Mobile Limited. All Rights Reserved
 * File			: CommonAutomatedTestController.m
 *
 * Description	: 常用自动化测试主控制器
 *
 * Author		: daijb@ucweb.com
 * History		:
 *			   Creation, 2014/03/14, daijb, Create the file
 ******************************************************************************
 **/
#if defined(UC_COMMON_AUTOMATED_TEST) || defined(UC_MONKEY_TEST)
#import "VerDefine.h"


#import "CommonAutomatedTestController.h"
#import "UIGlobal.h"
#import "UIViewAdditions.h"
#import "ResManager.h"
#import "AutomatedItem/AutomatedItemPage.h"

#define kButtonWidthMargin 25.f

extern UIView* g_mainView;
extern UIViewController* g_rootViewController;

@interface CommonAutomatedTestController()

@property (nonatomic, retain) UIButton* testButton;

@end

@implementation CommonAutomatedTestController

#pragma mark - life cycle

+ (instancetype)shareInstance
{
    static dispatch_once_t onceToken = 0;
    static CommonAutomatedTestController* instance = nil;
    
    dispatch_once(&onceToken, ^{
        instance = [[CommonAutomatedTestController alloc] init];
    });
    
    return instance;
}

- (void)dealloc
{
    [_testButton release];
    _testButton = nil;
    
    [super dealloc];
}

#pragma mark - showPancel

- (void)showPanel
{
    self.testButton = [[[UIButton alloc] initWithFrame:CGRectMake(g_mainView.width - kButtonWidthMargin, g_mainView.size.height - [UIGlobal getBottombarRect].size.height - kButtonWidthMargin, kButtonWidthMargin, kButtonWidthMargin)] autorelease];
    self.testButton.showsTouchWhenHighlighted = YES;
    self.testButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    [self.testButton setImage:resGetImage(@"ToolBar/iconForward.png") forState:UIControlStateNormal];
    self.testButton.layer.cornerRadius = 5;
    self.testButton.layer.masksToBounds = YES;
    self.testButton.clipsToBounds = NO;
    self.testButton.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:0.3];
    self.testButton.accessibilityLabel = @"EnterCommonAutomatedTest";
    [self.testButton addTarget:self action:@selector(didButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [g_mainView addSubview:self.testButton];
}

- (void)didButtonClicked:(id)sender
{
    AutomatedItemPage* automatedItemPage = [[AutomatedItemPage alloc] initWithTitle:resGetText(@"CommonAutomatedTest/Title")];
    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:automatedItemPage];
    [g_rootViewController presentViewController:navController animated:YES completion:nil];
    [automatedItemPage release];
    [navController release];
}

@end
#endif
